#ifndef __DYNAMIC_MEMORY_HPP__
#define __DYNAMIC_MEMORY_HPP__

#include <cstdlib>
#include <cstdint>

namespace Utils
{
    class DynamicMemory
    {
    public:
        DynamicMemory(uint32_t buffSize = 1024);
        ~DynamicMemory();

        inline void setBuffSize(uint32_t buffSize);
        inline uint32_t getBuffSize();
        inline char *getBuffer();

    private:
        char *m_buffer;
        uint32_t m_buffSize;
    };

    inline DynamicMemory::DynamicMemory(uint32_t buffSize) : m_buffSize(buffSize)
    {
        m_buffer = (char *)malloc(m_buffSize);
    }
    inline DynamicMemory::~DynamicMemory()
    {
        free(m_buffer);
    }
    inline void DynamicMemory::setBuffSize(uint32_t buffSize)
    {
        if (buffSize > m_buffSize)
        {
            free(m_buffer);
            m_buffSize = buffSize;
            m_buffer = (char *)malloc(m_buffSize);
        }
    }
    inline uint32_t DynamicMemory::getBuffSize()
    {
        return m_buffSize;
    }
    inline char *DynamicMemory::getBuffer()
    {
        return m_buffer;
    }
}

#endif